import io

import ddddocr
import requests
from PIL import Image
session = requests.Session ()
slide = ddddocr.DdddOcr(det=False,ocr=False,show_ad=False)

res_img = session.get("https://bm.ruankao.org.cn/sign/captchaImg?0.42257613114299786")

with open("static/slide/three.png","wb") as f:
    f.write(res_img.content)

three_img = Image.open("static/slide/three.png")

#背景图
background_img = three_img.crop((0,0,240,150))
background_bytes = io.BytesIO()
background_img.save(background_bytes,"png")



#滑块
target_img = three_img.crop((0,150,51,300))
target_bytes = io.BytesIO()
target_img.save(target_bytes,"png")


full_img = three_img.crop((0,300,240,450))
full_img_bytes = io.BytesIO()
full_img.save(full_img_bytes,"png")

res_slide = slide.slide_match(target_bytes.getvalue(), background_bytes.getvalue())
slide_distance = res_slide['target'][0]
print(res_slide['target'][0])
# res_slide = slide.slide_comparison(background_bytes.getvalue(), full_img_bytes.getvalue())
# print(res_slide)

#开始验证
res = session.post(f"https://bm.ruankao.org.cn/sign/checkTnCode?p={slide_distance}")
print(res.json())

datas = {
    "s1":"MjMyMzQxMjM0MTIzNDIz",
"s2": "3daa872a5c40024acce2f563457ad5dc",

"s3": f"{slide_distance}"


}
res_login = session.post("https://bm.ruankao.org.cn/sign/inok",data=datas)

print(res_login.json())













































